class Singleton {
    //先不初始化
    private static volatile Singleton instance = null;

    //创建锁对象
    private static Object locker = new Object();

    private Singleton() {

    }

    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (locker) {
                if (instance == null) {//若实例未初始化就先初始化
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}

public class Demo5 {

}
